package cn.itcast.interceptor;

import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
* @PackageName:cn.itcast.interceptor
* 自定义拦截器
* @Class:MyInterceptor1
* @author:ledehui
* @Date:2020/11/2 15:15
*/
public class MyInterceptor2 implements HandlerInterceptor{

    /**
     * 预处理，controller方法执行前
     * return true  放行，执行下一个拦截器，日过没有就执行controller中的方法
     * return false 不放行
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle...MyInterceptor1.....222");
//        request.getRequestDispatcher("/WEB-INF/pages/error.jsp").forward( request,response);
        return true;
    }

    /**
     * 后处理方法
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle....后...222");
//        request.getRequestDispatcher("/WEB-INF/pages/error.jsp").forward( request,response);

    }

    /**
     * success.jsp页面执行后，该方法会执行
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
        System.out.println("afterCompletion....final...222");

    }
}
